﻿namespace Journey.Adapter
{
    using AutoMapper;

    /// <summary>
    /// 类型自动映射适配器。
    /// </summary>
    public class AutomapperTypeAdapter : ITypeAdapter
    {
        /// <summary>
        /// 对象映射。
        /// </summary>
        /// <typeparam name="TTarget">目标类型。</typeparam>
        /// <param name="source">源对象。</param>
        /// <returns>目标对象。</returns>
        public TTarget Adapt<TTarget>(object source) where TTarget : class, new()
        {
            return Mapper.Map<TTarget>(source);
        }

        /// <summary>
        /// 对象映射。
        /// </summary>
        /// <typeparam name="TSource">源类型。</typeparam>
        /// <typeparam name="TTarget">目标类型。</typeparam>
        /// <param name="source">源对象。</param>
        /// <returns>目标对象。</returns>
        public TTarget Adapt<TSource, TTarget>(TSource source)
            where TSource : class
            where TTarget : class, new()
        {
            return Mapper.Map<TSource, TTarget>(source);
        }
    }
}